﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VectorPicsEditor
{
    public partial class ResizeWindow : Form
    {
        private int origionalW, origionalH;
        //private bool looping;

        public ResizeWindow(int width, int height)
        {
            InitializeComponent();
            widthBox.Text = width.ToString();
            heightBox.Text = height.ToString();
            origionalH = height;
            origionalW = width;
        }

        private void widthBox_TextChanged(object sender, EventArgs e)
        {
            if (!widthBox.Focused)
                return;

            int val;
            if (!int.TryParse(widthBox.Text, out val))
            {
                OKButton.Enabled = false;
            }
            else
            {
                OKButton.Enabled = true;
                if (ratioChecker.Checked)
                {
                    heightBox.Text = ((int)((double)val * (double)origionalH / (double)origionalW)).ToString();
                }
            }
        }

        private void heightBox_TextChanged(object sender, EventArgs e)
        {
            if (!heightBox.Focused)
                return;

            int val;
            if (!int.TryParse(heightBox.Text, out val))
            {
                OKButton.Enabled = false;
            }
            else
            {
                OKButton.Enabled = true;
                if (ratioChecker.Checked)
                {
                    widthBox.Text = ((int)((double)val * (double)origionalW / (double)origionalH)).ToString();
               //     looping = true;
                }
            }
        }

        public int GetWidth()
        {
            return int.Parse(widthBox.Text);
        }

        public int GetHeight()
        {
            return int.Parse(heightBox.Text);
        }

        public bool RatioChecker
        {
            get
            {
                return ratioChecker.Visible;
            }
            set
            {
                ratioChecker.Visible = value;
            }
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}
